﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using Composite.Data;
using $myprojectname$.Domain.Abstract;
using $myprojectname$.Domain.Entities;
using C1 = Domain.Entities.C1;
using AutoMapper;

namespace $myprojectname$.Domain
{
    public class ProductRepository: IProductRepository
    {
        #region Constructors

        public ProductRepository()
        {
            // DTO and business entity mappings.
			CreateMappings();
        }

        #endregion
        
        public IEnumerable<Product> GetProducts()
        {
            try
            {
                 using (var connection = new DataConnection())
                 {
                     var products = from p in connection.Get<C1.Product>()
                                  select p;

                     return Mapper.Map<IEnumerable<C1.Product>, IEnumerable<Product>>(products);
                 }
            }
            catch (Exception ex)
            {
                throw new Exception(ex.Message.ToString());
            }
        }

        #region Private Methods

		private void CreateMappings()
		{
		   Mapper.CreateMap<C1.Product, Product>();
		}

        #endregion
    }
}
